package com.zlsf.service;

import io.vertx.core.net.NetSocket;

import java.util.HashMap;
import java.util.Map;

public final class SessionManager {
  private static final Map<String, Object> mappings = new HashMap<>();

  private static final Map<String, NetSocket> channels = new HashMap<>();

  public static void init() {
    // ...
  }

  public static <T> T get(String channelId, String key) {
    return (T) mappings.get(channelId + key);
  }

  public static void set(String channelId, String key, Object value) {
    mappings.put(channelId + key, value);
  }

  public static void setChannel(NetSocket channel, String value) {
    channels.put(value, channel);
  }

  public static boolean contains(String channelId, String key) {
    return mappings.containsKey(channelId + key);
  }

  public static void remove(String channelId, String key) {
    mappings.remove(channelId + key);
  }

  public static void removeChannel(String tag) {
    NetSocket channel = channels.get(tag);
    if (channel != null) {
      channel.close();
      channels.remove(tag);
    }
  }
}
